package com.aurora.oa.customview;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aurora.oa.R;

/**
 * Created by Administrator on 2017/3/15 0015.
 */
public class TopImageItem extends LinearLayout{
    LinearLayout ll_background;
    TextView tv_title;
    TextView tv_subTitle;
    ImageView iv_image;
    private String namespace = "http://schemas.android.com/apk/res-auto";
    public TopImageItem(Context context) {
        this(context,null);
    }

    public TopImageItem(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public TopImageItem(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view = LayoutInflater.from(context).inflate(R.layout.view_top_image_item, this, true);
        tv_title = (TextView) view.findViewById(R.id.tv_title);
        tv_subTitle =(TextView) view.findViewById(R.id.tv_subtitle);
        iv_image =(ImageView) view.findViewById(R.id.iv_item);
        ll_background = (LinearLayout)  view.findViewById(R.id.ll_background);
        String title = attrs.getAttributeValue(namespace,"image_item_title");
        String subtitle = attrs.getAttributeValue(namespace,"sub_title");
        int backgroundId = attrs.getAttributeResourceValue(namespace,"item_background",0);
        int imageID =attrs.getAttributeResourceValue(namespace,"img_src",0);
        tv_title.setText(title);
        tv_subTitle.setText(subtitle);
        iv_image.setImageResource(imageID);
        if(backgroundId!=0){
            ll_background.setBackgroundResource(backgroundId);
        }
    }

}
